﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace Leek
{
    public static class CompositionContainer
    {
        private static readonly Dictionary<Type, object> _objects;


        [Pure]
        public static T GetInstance<T>()
        {
            var type = typeof(T);
            if (_objects.ContainsKey(type))
                return (T)_objects[type];
            else
                throw new CompositionInstanceNotFoundException();
        }


        public static void RegisterInstance<T>(T instance)
        {
            _objects[typeof(T)] = instance;
        }


        static CompositionContainer()
        {
            _objects = new Dictionary<Type, object>();
        }
    }
}
